import 'dart:io';

import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io' show Platform;

import 'package:path_provider/path_provider.dart';

// 获取公共路径
Future<Directory?> getBengBengSavePublicPath() async {
  if (Platform.isAndroid) {
    return await getAndroidPublicPath();
  } else if (Platform.isIOS) {
    return await getiOSPublicPath();
  } else if (Platform.isWindows) {
    return await getWinDesktopPublicPath();
  } else if (Platform.isMacOS) {
    return await getMacDesktopPublicPath();
  }
  return await getDownloadsDirectory();
}

// 在 Android 平台上获取公共路径的具体实现
Future<Directory?> getAndroidPublicPath() async {
  return await getExternalStorageDirectory();
}

// 在 iOS 平台上获取公共路径的具体实现
Future<Directory?> getiOSPublicPath() async {
  return await getApplicationDocumentsDirectory();
}

// 在 Windows 和 macOS 平台上获取公共路径的具体实现
Future<Directory?> getWinDesktopPublicPath() async {
  return await getApplicationDocumentsDirectory();
}
///~/Library/Containers/com.example.nasLog/Data/Documents/nas_log/log2023711.txt
// 在 Web 平台上获取公共路径的具体实现
Future<Directory?> getMacDesktopPublicPath() async {
  return await getApplicationDocumentsDirectory();
}

String getNameStr() {
  final now = DateTime.now();
  return "${now.year}${now.month}${now.day}";
}
